package threadDemo1.setDaemon;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-27
 * Time: 02:05
 */
public class ThreadDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            while (true) {
                try {
                    Thread.sleep(1000);
                    System.out.println("Hello Thread");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        //把thread设置为后台线程，不会阻止主线程的结束,thread线程会伴随main线程的结束而结束
        thread.setDaemon(true);
        thread.start();
        System.out.println("Hello Main");
    }
}
